import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';

let app: any = null;

function render(props: any = {}) {
  const { container } = props;
  app = createApp(App);
  app.use(router);
  app.use(ElementPlus);
  // 使用传入的容器或默认挂载点
  app.mount(container ? container.querySelector('#sub-app') : '#sub-app');
}

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
}

renderWithQiankun({
  bootstrap() {},
  mount(props) {
    render(props);
  },
  unmount() {
    app?.unmount();
  },
});
